<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>08-改变Y轴正方向</title>
    <style>
        canvas{
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="800" height="600"></canvas>
    <script>
        var canvas = document.getElementById("canvas")
        var ctx = canvas.getContext("2d")
        console.log(ctx)
        var xy = [
                [100,100,"   随便写点东西0"],
                [200,500,"   随便写点东西1"],
                [300,100,"   随便写点东西2"],
                [400,500,"   随便写点东西3"],
                [500,200,"   随便写点东西4"],
                [600,500,"   随便写点东西5"]
        ]
        changeXY(xy)
        xy.sort(function (a,b) {
            return a[1]<b[1]
        })
        console.table(xy)
        function changeXY(arr1) {
            ctx.beginPath()
            ctx.translate(0,canvas.height)
            for (var i = 1; i < arr1.length; i++) {
                ctx.moveTo(arr1[i-1][0],-arr1[i-1][1])
                ctx.lineTo(arr1[i][0],-arr1[i][1])
                ctx.stroke()
                ctx.beginPath()
                ctx.arc(arr1[i][0],-arr1[i][1],2,0,2*Math.PI)
                ctx.fill()
                ctx.fillText(arr1[i-1][2],arr1[i-1][0],-arr1[i-1][1])
            }
            ctx.fillText(arr1[i-1][2],arr1[i-1][0],-arr1[i-1][1])

        }


    </script>
</body>
</html>